package com.hongliang.mockito.lesson9;

import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.hamcrest.Factory;

import javax.xml.parsers.SAXParserFactory;

/**
 * @author Hongliang Zhu
 * @create 2021-08-15 16:34
 */
public class GreaterThan<T extends Number> extends BaseMatcher<T> {

    private final T value;

    public GreaterThan(T value) {
        this.value = value;
    }

    @Override
    public boolean matches(Object actual) {

        if(actual instanceof  Comparable){
            return ((Comparable) actual).compareTo(value) > 0;
        }else{
            throw new AssertionError("Not supported!");
        }

//        Class<?> clazz = actual.getClass();

//        if (clazz == Integer.class){
//            return (Integer)actual > (Integer)value;
//        }else if (clazz == Long.class){
//            return (Long)actual > (Long)value;
//        }else if (clazz == Byte.class){
//            return (Byte)actual > (Byte)value;
//        }else if (clazz == Long.class){
//            return (Long)actual > (Long)value;
//        }else if (clazz == Long.class){
//            return (Long)actual > (Long)value;
//        }

//        return false;
    }

    @Factory
    public static <T extends Number>  GreaterThan<T> gt(T value){
        return new GreaterThan<>(value);
    }

    @Override
    public void describeTo(Description description) {

    }
}
